home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / include / Ecore_Ipc.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-01-09  |  9.0 KB  |  318 lines

  1. #ifndef _ECORE_IPC_H
  2. #define _ECORE_IPC_H
  3.  
  4. #ifdef EAPI
  5. #undef EAPI
  6. #endif
  7. #ifdef WIN32
  8. # ifdef BUILDING_DLL
  9. #  define EAPI __declspec(dllexport)
  10. # else
  11. #  define EAPI __declspec(dllimport)
  12. # endif
  13. #else
  14. # ifdef __GNUC__
  15. #  if __GNUC__ >= 4
  16. #   define EAPI __attribute__ ((visibility("default")))
  17. #  else
  18. #   define EAPI
  19. #  endif
  20. # else
  21. #  define EAPI
  22. # endif
  23. #endif
  24.  
  25. /**
  26.  * @file Ecore_Ipc.h
  27.  * @brief Ecore inter-process communication functions.
  28.  */
  29.  
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33.  
  34. #ifndef _ECORE_IPC_PRIVATE_H
  35.    typedef void Ecore_Ipc_Server; /**< An IPC connection handle */
  36.    typedef void Ecore_Ipc_Client; /**< An IPC connection handle */
  37. #endif
  38.  
  39. /**
  40.  * Macros used for generic data packing
  41.  */
  42. EAPI unsigned short _ecore_ipc_swap_16(unsigned short v);
  43. EAPI unsigned int _ecore_ipc_swap_32(unsigned int v);
  44. EAPI unsigned long long _ecore_ipc_swap_64(unsigned long long v);
  45.  
  46. #ifdef WORDS_BIGENDIAN
  47. #define ECORE_IPC_SWAP2NET64(x) _ecore_ipc_swap_64(x)
  48. #define ECORE_IPC_SWAP2CPU64(x) _ecore_ipc_swap_64(x)
  49. #define ECORE_IPC_SWAP2NET32(x) _ecore_ipc_swap_32(x)
  50. #define ECORE_IPC_SWAP2CPU32(x) _ecore_ipc_swap_32(x)
  51. #define ECORE_IPC_SWAP2NET16(x) _ecore_ipc_swap_16(x)
  52. #define ECORE_IPC_SWAP2CPU16(x) _ecore_ipc_swap_16(x)
  53. #define ECORE_IPC_SWAP2NET8(x) (x)
  54. #define ECORE_IPC_SWAP2CPU8(x) (x)
  55. #else
  56. #define ECORE_IPC_SWAP2NET64(x) (x)
  57. #define ECORE_IPC_SWAP2CPU64(x) (x)
  58. #define ECORE_IPC_SWAP2NET32(x) (x)
  59. #define ECORE_IPC_SWAP2CPU32(x) (x)
  60. #define ECORE_IPC_SWAP2NET16(x) (x)
  61. #define ECORE_IPC_SWAP2CPU16(x) (x)
  62. #define ECORE_IPC_SWAP2NET8(x) (x)
  63. #define ECORE_IPC_SWAP2CPU8(x) (x)
  64. #endif
  65.  
  66. /* 1, 2, 4 and 8 byte datatypes */
  67. /* unpacking */
  68. #define ECORE_IPC_GET64(v)\
  69.     { \
  70.     p->v = ECORE_IPC_SWAP2CPU64(*(long long *)(ptr)); \
  71.     ptr += 8; \
  72.     }
  73. #define ECORE_IPC_GET32(v)\
  74.     { \
  75.     p->v = ECORE_IPC_SWAP2CPU32(*(int *)(ptr)); \
  76.     ptr += 4; \
  77.     }
  78. #define ECORE_IPC_GET16(v)\
  79.     { \
  80.     p->v = ECORE_IPC_SWAP2CPU16(*(short *)(ptr)); \
  81.     ptr += 2; \
  82.     }
  83. #define ECORE_IPC_GET8(v) \
  84.     { \
  85.     p->v = ECORE_IPC_SWAP2CPU8(*(char *)(ptr)); \
  86.     ptr += 1; \
  87.     }
  88. /* packing */
  89. #define ECORE_IPC_PUT64(v)\
  90.     { \
  91.     *(long long *)(ptr) = ECORE_IPC_SWAP2NET64(p->v); \
  92.     ptr += 8; \
  93.     }
  94. #define ECORE_IPC_PUT32(v)\
  95.     { \
  96.     *(int *)(ptr) = ECORE_IPC_SWAP2NET32(p->v); \
  97.     ptr += 4; \
  98.     }
  99. #define ECORE_IPC_PUT16(v)\
  100.     { \
  101.     *(short *)(ptr) = ECORE_IPC_SWAP2NET16(p->v); \
  102.     ptr += 2; \
  103.     }
  104. #define ECORE_IPC_PUT8(v) \
  105.     { \
  106.     *(char *)(ptr) = ECORE_IPC_SWAP2NET8(p->v); \
  107.     ptr += 1; \
  108.     }
  109. /* padding data */
  110. #define ECORE_IPC_PAD8()   ptr += 1
  111. #define ECORE_IPC_PAD16()  ptr += 2
  112. #define ECORE_IPC_PAD32()  ptr += 4
  113. #define ECORE_IPC_PAD64()  ptr += 8
  114.  
  115. /* counting data when encoding lists */
  116. #define ECORE_IPC_CNT8()    len += 1
  117. #define ECORE_IPC_CNT16()   len += 2
  118. #define ECORE_IPC_CNT32()   len += 4
  119. #define ECORE_IPC_CNT64()   len += 8
  120.  
  121. /* strings */
  122. #define ECORE_IPC_CHEKS() if (*((unsigned char *)d + s - 1) != 0) return 0;
  123. #define ECORE_IPC_GETS(v) \
  124.     { \
  125.     if (ptr < ((unsigned char *)d + s)) \
  126.         { \
  127.         p->v = (char *)ptr; \
  128.         ptr += strlen(p->v) + 1; \
  129.         } \
  130.     } 
  131. #define ECORE_IPC_PUTS(v, l)\
  132.     { \
  133.     strcpy((char *)ptr, p->v); \
  134.     ptr += l + 1; \
  135.     }
  136.  
  137. /* handy to calculate what sized block we need to alloc */
  138. #define ECORE_IPC_SLEN(l, v) ((l = strlen(p->v)) + 1)
  139. #define ECORE_IPC_CNTS(v)   len += strlen(p->v) + 1
  140.  
  141. /* saves typing function headers */
  142. #define ECORE_IPC_DEC_STRUCT_PROTO(x) static int x(void *d, int s, void *pp)
  143. #define ECORE_IPC_ENC_STRUCT_PROTO(x) static void *x(void *pp, int *s)
  144. #define ECORE_IPC_DEC_EVAS_LIST_PROTO(x) static Evas_List *x(void *d, int s)
  145. #define ECORE_IPC_ENC_EVAS_LIST_PROTO(x) static void *x(Evas_List *lp, int *s)
  146.  
  147.  
  148. /* decoder setup - saves typing. requires data packet of exact size, or fail */
  149. #define ECORE_IPC_DEC_STRUCT_HEAD_EXACT(typ, x) \
  150.     typ *p; \
  151.     unsigned char *ptr; \
  152.     p = (typ *)pp; \
  153.     if (!d) return 0; if (s != (x)) return 0; \
  154.     ptr = d;
  155. /* decoder setup - saves typing. requires data packet of a minimum size */
  156. #define ECORE_IPC_DEC_STRUCT_HEAD_MIN(typ, x) \
  157.     typ *p; \
  158.     unsigned char *ptr; \
  159.     p = (typ *)pp; \
  160.     if (!d) return 0; if (s < (x)) return 0; \
  161.     ptr = d;
  162. /* footer for the hell of it */
  163. #define ECORE_IPC_DEC_STRUCT_FOOT() return 1
  164. /* header for encoder - gives native strct type and size of flattened packet */
  165. #define ECORE_IPC_ENC_STRUCT_HEAD(typ, sz) \
  166.     typ *p; \
  167.     unsigned char *d, *ptr; \
  168.     int len; \
  169.     *s = 0; \
  170.     if(!pp) return NULL; \
  171.     p = (typ *)pp; \
  172.     len = sz; \
  173.     d = malloc(len); \
  174.     if (!d) return NULL; \
  175.     *s = len; \
  176.     ptr = d;
  177. /* footer for the hell of it */
  178. #define ECORE_IPC_ENC_STRUCT_FOOT() return d
  179.  
  180. #define ECORE_IPC_DEC_EVAS_LIST_HEAD(typ) \
  181.     unsigned char *ptr; \
  182.     Evas_List *l; \
  183.     typ *p; \
  184.     l = NULL; \
  185.     ptr = d; \
  186.     while(ptr < (unsigned char *)(d + s)) \
  187.         { \
  188.             p = malloc(sizeof(typ));
  189.  
  190. #define ECORE_IPC_DEC_EVAS_LIST_FOOT() \
  191.         l = evas_list_append(l, p); \
  192.         } \
  193.     return l
  194. #define ECORE_IPC_ENC_EVAS_LIST_HEAD_START(typ) \
  195.     Evas_List *l; \
  196.     typ *p; \
  197.     unsigned char *d, *ptr; \
  198.     int len; \
  199.     *s = 0; \
  200.     len = 0; \
  201.     for (l = lp; l; l = l->next) \
  202.       { \
  203.          p = l->data;
  204. #define ECORE_IPC_ENC_EVAS_LIST_HEAD_FINISH() \
  205.       } \
  206.     d = malloc(len); \
  207.     if(!d) return NULL; \
  208.     *s = len; \
  209.     ptr = d; \
  210.     for (l = lp; l; l = l->next) \
  211.       { \
  212.          p = l->data;
  213.  
  214. #define ECORE_IPC_ENC_EVAS_LIST_FOOT() \
  215.       } \
  216.    return d
  217.  
  218.    typedef enum _Ecore_Ipc_Type
  219.      {
  220.     ECORE_IPC_LOCAL_USER,
  221.       ECORE_IPC_LOCAL_SYSTEM,
  222.       ECORE_IPC_REMOTE_SYSTEM,
  223.           ECORE_IPC_USE_SSL = 16
  224.      } Ecore_Ipc_Type;
  225.    
  226.    typedef struct _Ecore_Ipc_Event_Client_Add  Ecore_Ipc_Event_Client_Add;
  227.    typedef struct _Ecore_Ipc_Event_Client_Del  Ecore_Ipc_Event_Client_Del;
  228.    typedef struct _Ecore_Ipc_Event_Server_Add  Ecore_Ipc_Event_Server_Add;
  229.    typedef struct _Ecore_Ipc_Event_Server_Del  Ecore_Ipc_Event_Server_Del;
  230.    typedef struct _Ecore_Ipc_Event_Client_Data Ecore_Ipc_Event_Client_Data;
  231.    typedef struct _Ecore_Ipc_Event_Server_Data Ecore_Ipc_Event_Server_Data;
  232.    
  233.    struct _Ecore_Ipc_Event_Client_Add
  234.      {
  235.     Ecore_Ipc_Client *client;
  236.      };
  237.    
  238.    struct _Ecore_Ipc_Event_Client_Del
  239.      {
  240.     Ecore_Ipc_Client *client;
  241.      };
  242.    
  243.    struct _Ecore_Ipc_Event_Server_Add
  244.      {
  245.     Ecore_Ipc_Server *server;
  246.      };
  247.    
  248.    struct _Ecore_Ipc_Event_Server_Del
  249.      {
  250.     Ecore_Ipc_Server *server;
  251.      };
  252.    
  253.    struct _Ecore_Ipc_Event_Client_Data
  254.      {
  255.     Ecore_Ipc_Client *client;
  256.     /* FIXME: this needs to become an ipc message */
  257.     int               major;
  258.     int               minor;
  259.     int               ref;
  260.     int               ref_to;
  261.     int               response;
  262.     void             *data;
  263.     int               size;
  264.      };
  265.    
  266.    struct _Ecore_Ipc_Event_Server_Data
  267.      {
  268.     Ecore_Ipc_Server *server;
  269.     /* FIXME: this needs to become an ipc message */
  270.     int               major;
  271.     int               minor;
  272.     int               ref;
  273.     int               ref_to;
  274.     int               response;
  275.     void             *data;
  276.     int               size;
  277.      };
  278.    
  279.    EAPI extern int ECORE_IPC_EVENT_CLIENT_ADD;
  280.    EAPI extern int ECORE_IPC_EVENT_CLIENT_DEL;
  281.    EAPI extern int ECORE_IPC_EVENT_SERVER_ADD;
  282.    EAPI extern int ECORE_IPC_EVENT_SERVER_DEL;
  283.    EAPI extern int ECORE_IPC_EVENT_CLIENT_DATA;
  284.    EAPI extern int ECORE_IPC_EVENT_SERVER_DATA;
  285.    
  286.    EAPI int               ecore_ipc_init(void);
  287.    EAPI int               ecore_ipc_shutdown(void);
  288.    
  289.    /* FIXME: need to add protocol type parameter */
  290.    EAPI Ecore_Ipc_Server *ecore_ipc_server_add(Ecore_Ipc_Type type, const char *name, int port, const void *data);
  291.    
  292.    /* FIXME: need to add protocol type parameter */
  293.    EAPI Ecore_Ipc_Server *ecore_ipc_server_connect(Ecore_Ipc_Type type, char *name, int port, const void *data);
  294.    EAPI void             *ecore_ipc_server_del(Ecore_Ipc_Server *svr);
  295.    EAPI void             *ecore_ipc_server_data_get(Ecore_Ipc_Server *svr);
  296.    EAPI int               ecore_ipc_server_connected_get(Ecore_Ipc_Server *svr);
  297.    /* FIXME: this needs to become an ipc message */
  298.    EAPI int               ecore_ipc_server_send(Ecore_Ipc_Server *svr, int major, int minor, int ref, int ref_to, int response, void *data, int size);
  299.    EAPI void              ecore_ipc_server_client_limit_set(Ecore_Ipc_Server *svr, int client_limit, char reject_excess_clients);
  300.    EAPI void              ecore_ipc_server_disown(Ecore_Ipc_Server *svr);
  301.    
  302.    /* FIXME: this needs to become an ipc message */
  303.    EAPI int               ecore_ipc_client_send(Ecore_Ipc_Client *cl, int major, int minor, int ref, int ref_to, int response, void *data, int size);
  304.    EAPI Ecore_Ipc_Server *ecore_ipc_client_server_get(Ecore_Ipc_Client *cl);
  305.    EAPI void             *ecore_ipc_client_del(Ecore_Ipc_Client *cl);
  306.    EAPI void              ecore_ipc_client_data_set(Ecore_Ipc_Client *cl, const void *data);
  307.    EAPI void             *ecore_ipc_client_data_get(Ecore_Ipc_Client *cl);
  308.    
  309.    EAPI int               ecore_ipc_ssl_available_get(void);
  310.    /* FIXME: need to add a callback to "ok" large ipc messages greater than */
  311.    /*        a certain size (seurity/DOS attack safety) */
  312.    
  313. #ifdef __cplusplus
  314. }
  315. #endif
  316.  
  317. #endif
  318.